﻿<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(APPPATH.'libraries/FirePHPCore/FirePHP.class.php');
ob_start();

class User extends CI_Controller {

    function __construct()
    {
        parent::__construct();
		$this->firephp = FirePHP::getInstance(true);
		$this->load->model('User_model', 'user');
    }

	public function login()
	{
		$css[]['src']="jquery/jqueryui/smoothness/jquery-ui-1.8.17.custom.css";
		$css[]['src']="jquery/jQuery-Validation/css/validationEngine.jquery.css";
		$css[]['src']="jquery/jQuery-Validation/css/template.css";
		$css[]['src']="css/login.css";
		
		
        $js[]['src']="jquery/jquery-1.7.1.min.js";
        $js[]['src']="jquery/jqueryui/jquery-ui-1.8.17.custom.min.js";
		$js[]['src']="jquery/jquery.form.js";
		$js[]['src']="jquery/jQuery-Validation/js/languages/jquery.validationEngine-en.js";
		$js[]['src']="jquery/jQuery-Validation/js/jquery.validationEngine.js";
				
		$data['css']=$css;
        $data['js']=$js;
        $data['page']['title'] = 'My Blog Title';
        $data['page']['heading'] = 'My Blog Heading';
        
        $this->load->view('layout/header',$data);
        $this->load->view('user/form_login',$data);
        $this->load->view('layout/footer',$data);
	}
	
	public function check_user()
	{
		$user=$this->input->post('login_user');
		$pwd=$this->input->post('login_pwd');
		if((empty($user)) or (empty($pwd))) {
			$response['status']='FALSE';
			$response['error']='กรอกข้อมูลไม่ครบ';
		}else{
			$data_user=$this->user->check_login($user,$pwd);
			
			if($data_user !== FALSE){
				$this->session->set_userdata($data_user);
				$this->firephp->log($data_user);
				$response['status']='complete';
			}else{
				$this->session->sess_destroy();
				$response['status']='FALSE';
				$response['error']='ข้อมูลไม่ถูกต้อง';
			}
		}
		echo json_encode($response);
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */